import datetime

import jwt
from django.conf import settings


class ToolJWT:
    def getjwt(self,userdata):
        # 设置过期时间
        userdata["exp"]=datetime.datetime.utcnow()+datetime.timedelta(hours=2)
        # 生成jwt
        key=settings.SECRET_KEY
        jwt_token=jwt.encode(userdata,key,algorithm='HS256')
        return jwt_token
    def decodejwt(self,token):
        key=settings.SECRET_KEY
        jwt_decode=jwt.decode(token,key,algorithms='HS256')
        return jwt_decode
tooljwt=ToolJWT()